package com.lagou.filter;


import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

import javax.swing.*;
import java.util.Map;

@Activate(group = {CommonConstants.CONSUMER})
public class TransportIPFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        //获取参数
        String ip = (String) RpcContext.getContext().get("ip");

        // 远程调用之前，通过attachment传KV给提供方
        RpcContext.getContext().setAttachment("ip", ip);

        //设置ip到RpcContext
        //System.out.println("过滤器得到的ip是："+ip);
        //RpcContext.getContext().set("ip", ip);
        try {
            return invoker.invoke(invocation);
        }finally {
            //System.out.println("localHost:::"+localHost+";port:::"+localPort);
        }
    }

}
